package com.example.myapplication_2.a600_xm.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication_2.R;
import com.example.myapplication_2.a600_xm.adapter.ContactAdapter;
import com.example.myapplication_2.a600_xm.db.Z_ShoppingInfoDao;
import com.example.myapplication_2.a600_xm.db.dbbean.Life_Shopping;

import java.util.List;

import butterknife.ButterKnife;



public class F11_Fragment extends Fragment {

    View view;
    Z_ShoppingInfoDao z_shoppingInfoDao;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {

            view = View.inflate(getActivity(), R.layout.fragment_f5, null);
            ButterKnife.bind(this, view);
//            EventBus.getDefault().register(this);
            RecyclerView recList = (RecyclerView) view.findViewById(R.id.cardList);
            recList.setHasFixedSize(true);
            GridLayoutManager llm = new GridLayoutManager(getActivity(), 4);
            llm.setOrientation(LinearLayoutManager.VERTICAL);
            recList.setLayoutManager(llm);


            z_shoppingInfoDao = new Z_ShoppingInfoDao(getActivity());
//            createList();
            ContactAdapter ca = new ContactAdapter(createList());
            recList.setAdapter(ca);
        }
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }


        return view;
    }


    private List<Life_Shopping> createList() {

//        List<ContactInfo> result = new ArrayList<ContactInfo>();
        List<Life_Shopping> query = z_shoppingInfoDao.query("止泄类");


        return query;
    }
}